package com.lehecai.core.game;

import com.lehecai.core.IntegerBeanLabelItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 物品类型
 * @author He Wang
 */
public class ItemType extends IntegerBeanLabelItem {

	private static final long serialVersionUID = 235209907031088823L;
	private static final Logger logger = LoggerFactory.getLogger(ItemType.class.getName());

    private static List<ItemType> items = new ArrayList<ItemType>();
    private static List<ItemType> queryItems = new ArrayList<ItemType>();

    protected ItemType(String name, int value) {
        this(name, value, false);
    }

    protected ItemType(String name, int value, boolean queryOnly) {
        super(ItemType.class.getName(), name, value);
        queryItems.add(this);
        
        if (!queryOnly) {
            items.add(this);
        }
    }

    public static ItemType getItem(int value){
        try {
            return (ItemType)ItemType.getResult(ItemType.class.getName(), value);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static List<ItemType> getItems() {
        return items;
    }

    public static List<ItemType> getQueryItems() {
        return queryItems;
    }

    public static final ItemType ALL = new ItemType("全部", -1, true);
    public static final ItemType ITEM_TYPE_MONEY = new ItemType("游戏币", 1);
    public static final ItemType ITEM_TYPE_KIND = new ItemType("道具", 2);
}
